Learn how you can leverage versioning and optimistic locking in your indexing pipeline to guarantee data consistency, even in concurrent environments.
partialUpdateObjects
method. One process sends an update to set the stock of a product from 10
to 20
, because you just received ten new items in a shipment. Simultaneously, another process sets the stock for this product from 10
to 9
because of an order that just came in.
Depending on which job wins the race condition, the stock is now either 9
or 20
, even though the correct stock is 19
.
IncrementSet
operation. It lets you update an object only if you provide a higher numerical value than already exists in the record, or a value higher than 0 if the record doesn’t exist.
A great use-case for this is adding a Unix timestamp to your records. With IncrementSet
, the engine only updates your record if the timestamp you sent is more recent than the existing one. If you update in the meantime, you prevent the engine from overriding your record again; only the latest update is taken into account.
IncrementFrom
operation. It lets you update an object only if you provide the current version of the object, or 0 if the record doesn’t exist.
A typical use-case is when you perform a read-modify-write sequence:
IncrementFrom
operation with the old value of your versioning attribute.IncrementFrom
operation matches the current value currently in the record, and increments it. If another process incremented this value in the meantime, the engine ignores the update.
waitTask
API method.